<html>
<head><meta charset="utf-8"><title>Edition Request: let `1` be a float literal · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html">Edition Request: let `1` be a float literal</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="196235654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196235654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196235654">(May 04 2020 at 20:27)</a>:</h4>
<p>What I miss the most from Haskell is honestly just that you can just write <code>1</code> in a floating point position and it'll give you <code>1.0</code> like you wanted instead of giving you a compile error that says "I know what you meant but you have to put a dot on that number manually".</p>



<a name="196238737"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196238737" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Sebastian Malton <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196238737">(May 04 2020 at 20:53)</a>:</h4>
<p>That would be nice, namely <code>let x:f32 = 1;</code> would then work.</p>



<a name="196259436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196259436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196259436">(May 05 2020 at 01:25)</a>:</h4>
<p>Potential risk: That would mean that <code>1</code> would be both <code>{integer}</code> and <code>{float}</code>; I'm not sure how that might impact inference.</p>



<a name="196273268"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196273268" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196273268">(May 05 2020 at 06:57)</a>:</h4>
<p>I'd propose that, rather than immediately being "integer or float" the whole time, it's integer until an integer inference would fail, then at that moment the inference tries to continue as float until either that would also fail or things work out.</p>
<p>Though that doesn't fully mitigate the problem. It does make for an easy to explain rule at least.</p>



<a name="196275882"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196275882" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196275882">(May 05 2020 at 07:38)</a>:</h4>
<p>Inference fallbacks are already fiddly, adding more layers to it seems scary. What if we just said the <code>{integer}</code> pseudo-type can be constrained to any concrete float or int type, instead of just any concrete int type? Is there any situation where "this is some float or int type, don't know which one yet" leads to ambiguities but "this is some int type, don't know which one yet" doesn't?</p>



<a name="196284085"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196284085" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kennytm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196284085">(May 05 2020 at 09:13)</a>:</h4>
<blockquote>
<p>Is there any situation where "this is some float or int type, don't know which one yet" leads to ambiguities but "this is some int type, don't know which one yet" doesn't?</p>
</blockquote>
<div class="codehilite"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">Tr</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">impl</span><span class="w"> </span><span class="n">Tr</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="kt">u32</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="k">impl</span><span class="w"> </span><span class="n">Tr</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="kt">f32</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="mf">5.</span><span class="n">foo</span><span class="p">();</span><span class="w"> </span><span class="c1">// inference breakage if `{float}` has same priority as `{int}`</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="196284807"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196284807" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196284807">(May 05 2020 at 09:21)</a>:</h4>
<p>Okay, good point. Next question: is this something that is at all common in the real world? I recall a similar problem exists with allowing slice/array indexing with integer types other than <code>usize</code>, but I can't think of any cases where <em>one</em> integer type <em>and</em> some float types are an option. Much more common are "several/all int types" and "all numeric types (ints and floats)".</p>



<a name="196316235"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196316235" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196316235">(May 05 2020 at 14:35)</a>:</h4>
<p>There's also that at least some users may expect that 0 or 1 is an integer and 0.0 or 1.0 is a float.</p>



<a name="196316424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196316424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196316424">(May 05 2020 at 14:36)</a>:</h4>
<p>There's the standard tension between wanting the compiler to DWIM and wanting types kept strictly separated.</p>



<a name="196316507"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196316507" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196316507">(May 05 2020 at 14:37)</a>:</h4>
<p>well, in this instance, the type would be clearly assigned and not "mixable"</p>



<a name="196316538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196316538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196316538">(May 05 2020 at 14:37)</a>:</h4>
<p>I think that whenever this topic comes up, it behooves us to be very clear about the obstacles we're wary of</p>



<a name="196316703"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196316703" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196316703">(May 05 2020 at 14:38)</a>:</h4>
<p>"this topic" here means specifically "the tension about DWIM vs being strict"</p>



<a name="196331201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196331201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196331201">(May 05 2020 at 16:24)</a>:</h4>
<p>The common case that I encounter is that you're doing an operation, <code>x+=1</code> for example, and <code>x</code> has a type already and so there's no question as to what type <code>1</code> must be for the expression to become valid. Any type but a particular type is a compilation error.</p>



<a name="196333764"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196333764" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196333764">(May 05 2020 at 16:45)</a>:</h4>
<p>Right. The question then becomes, is the desired behavior "compilation error". For some users it may be.</p>



<a name="196335460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196335460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196335460">(May 05 2020 at 16:58)</a>:</h4>
<p>note though that we could plausibly solve that problem through a <code>Add</code> impl, though maybe not</p>



<a name="196335473"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196335473" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196335473">(May 05 2020 at 16:58)</a>:</h4>
<p>we have some limitations to the set of impls we can add</p>



<a name="196335800"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196335800" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196335800">(May 05 2020 at 17:01)</a>:</h4>
<p>@Josh: Sure, and that's perhaps a reasonable thing to want. I was more responding to Hanna's question of "what are the real world examples of this?"</p>
<p>If people <em>do</em> want to be extra hardline about things perhaps converting an int literal into being a float literal could also fire off an allow-by-default lint that a project could change to deny by default.</p>
<p>The Haskell community does get along just fine with <code>1 + 5.4</code> evaluating to <code>6.4</code> (also C and Python and basically the whole rest of the world, but Haskell specifically has a similar mentality to Rust of "absolute minimal implicit conversions")</p>
<p>@Niko: Well also: fields in a struct when you're initializing with a literal, or function args when you pass a literal to a function.</p>



<a name="196690999"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196690999" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196690999">(May 06 2020 at 20:16)</a>:</h4>
<p>re: "keep strictly separated", I think my main concern here would be precision loss</p>



<a name="196691032"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196691032" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196691032">(May 06 2020 at 20:16)</a>:</h4>
<p>so even if <code>1</code> becomes "float or int", I think integers that cannot be precisely represented in the target float point must <em>not</em> be turned into floats implicitly</p>



<a name="196691071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196691071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196691071">(May 06 2020 at 20:16)</a>:</h4>
<p>such loss of information should at least be explicitly acknowledged by appending <code>.0</code></p>



<a name="196691248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196691248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196691248">(May 06 2020 at 20:18)</a>:</h4>
<p>if we adopt that, since we are already accepting that  <code>5</code> might considered an element of <code>i32</code> or <code>u8</code>, I dont see any harm in also freely considering it an element of <code>f32</code> -- I dont think signed 32-bit and unsigned 8-bit integers are conceptually <em>that</em> much closer to each other than to <code>f32</code> to justify the distinction. people that want strict type separation should already be writing <code>5i32</code> for extra explicitness.</p>



<a name="196725138"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196725138" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196725138">(May 07 2020 at 04:00)</a>:</h4>
<p>Right, i suppose i was also assuming that the "overflowing literals" lint would apply here, the same as you can't use <code>0xFFF</code> in a <code>u8</code> position.</p>



<a name="196729165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196729165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kennytm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196729165">(May 07 2020 at 05:44)</a>:</h4>
<p>speaking of which, if <code>123</code> can be considered an <code>f32</code>, can <code>0xff</code> / <code>0o777</code> / <code>0b1010</code> be also be considered an <code>f32</code></p>



<a name="196731170"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196731170" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196731170">(May 07 2020 at 06:29)</a>:</h4>
<p>oof that's a big can of worms.</p>



<a name="196769842"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196769842" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Sebastian Malton <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196769842">(May 07 2020 at 13:30)</a>:</h4>
<p>I would say not since the reason for using binary, or octal, or hex is generally because you care about specific bit locations</p>



<a name="196788243"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196788243" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196788243">(May 07 2020 at 15:32)</a>:</h4>
<p>Advanced float math actually does use hex float literals because "advanced float math" means "very carefully weave the line between what CPUs do and how IEEE works".</p>



<a name="196788366"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196788366" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196788366">(May 07 2020 at 15:33)</a>:</h4>
<p>That said if we didn't have hex float literals in the "first round" of this change, or even ever, it'd be fine. You can use the "const union hack" in that rare case.</p>



<a name="196788894"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196788894" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196788894">(May 07 2020 at 15:37)</a>:</h4>
<p>It sounds like you're referring to e.g. specifying the smallest subnormal as <code>0x0000_0001</code> (which you can express today with <code>fN::from_bits</code>), but extrapolating the "<code>1</code> as float literal" feature to integer hexadecimal literals would instead suggest e.g. <code>0xff == 255.0</code> (which you can express today with <code>as</code> casts).</p>



<a name="196789087"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196789087" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196789087">(May 07 2020 at 15:38)</a>:</h4>
<p>I assumed everyone was referring to the latter. Making <code>let x: f32 = 0xff;</code> do something different from <code>let x: f32 = 255;</code> (if both work) seems very confusing.</p>



<a name="196790950"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196790950" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kennytm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196790950">(May 07 2020 at 15:51)</a>:</h4>
<p>one issue:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">a</span>: <span class="kt">f32</span> <span class="o">=</span><span class="w"> </span><span class="mi">123</span><span class="p">;</span><span class="w">       </span><span class="c1">// proposed for 2021.</span>
<span class="kd">let</span><span class="w"> </span><span class="n">b</span>: <span class="kt">f32</span> <span class="o">=</span><span class="w"> </span><span class="mi">123_</span><span class="k">f32</span><span class="p">;</span><span class="w">   </span><span class="c1">// works in 2015.</span>
<span class="kd">let</span><span class="w"> </span><span class="n">c</span>: <span class="kt">f32</span> <span class="o">=</span><span class="w"> </span><span class="mh">0xff</span><span class="p">;</span><span class="w">      </span><span class="c1">// proposed for 2021.</span>
<span class="kd">let</span><span class="w"> </span><span class="n">d</span>: <span class="kt">f32</span> <span class="o">=</span><span class="w"> </span><span class="mh">0xff_f32</span><span class="p">;</span><span class="w">  </span><span class="c1">// errrr....</span>
</code></pre></div>



<a name="196792348"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196792348" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196792348">(May 07 2020 at 16:00)</a>:</h4>
<p>ohno.jpg</p>



<a name="196793125"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196793125" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Sebastian Malton <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196793125">(May 07 2020 at 16:05)</a>:</h4>
<p>I would say that it would be better to do:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">a</span>: <span class="kt">f32</span> <span class="o">=</span><span class="w"> </span><span class="mi">123</span><span class="p">;</span><span class="w">       </span><span class="c1">// proposed for 2021.</span>
<span class="kd">let</span><span class="w"> </span><span class="n">b</span>: <span class="kt">f32</span> <span class="o">=</span><span class="w"> </span><span class="mi">123_</span><span class="k">f32</span><span class="p">;</span><span class="w">   </span><span class="c1">// works in 2015.</span>
<span class="kd">let</span><span class="w"> </span><span class="n">c</span>: <span class="kt">f32</span> <span class="o">=</span><span class="w"> </span><span class="mh">0xff</span><span class="p">;</span><span class="w">      </span><span class="c1">// errors now and in 2021</span>
<span class="kd">let</span><span class="w"> </span><span class="n">d</span>: <span class="kt">f32</span> <span class="o">=</span><span class="w"> </span><span class="mh">0xff_f32</span><span class="p">;</span><span class="w">  </span><span class="c1">// ^^^</span>
</code></pre></div>



<a name="196795827"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196795827" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Sebastian Malton <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196795827">(May 07 2020 at 16:25)</a>:</h4>
<p>Would people think that we have had enough discussion to write up an RFC.</p>
<p>I see the following points:</p>
<ol>
<li>Allow for base 10 numeric literals to be interpreted by the compiler as <code>{float}</code> if interpreting it as <code>{integer}</code> results in a type error. If both result in a type error, <em>only</em> report the <code>{integer}</code> type error.</li>
<li>Implement an <code>allow-by-default</code> lint for the above feature so that project that do not want to have this can disable it.</li>
</ol>



<a name="196795930"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196795930" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196795930">(May 07 2020 at 16:26)</a>:</h4>
<p>I agree with those points but I already am looking after about 1.5 RFCs so I wouldn't want to take on another right now.</p>



<a name="196796173"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196796173" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Sebastian Malton <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196796173">(May 07 2020 at 16:28)</a>:</h4>
<p>I would be fine doing the writeup</p>



<a name="196796253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196796253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196796253">(May 07 2020 at 16:29)</a>:</h4>
<p>There's a lang meeting later today and I'm not on the lang team but I can point them in the direction of this topic for them to check out when they get the time.</p>



<a name="196796257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196796257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kennytm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196796257">(May 07 2020 at 16:29)</a>:</h4>
<div class="codehilite"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">X</span>: <span class="nb">Sized</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">g</span><span class="p">(</span><span class="bp">self</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">impl</span><span class="w"> </span><span class="n">X</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="kt">f32</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">g</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;f32&quot;</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">impl</span><span class="w"> </span><span class="n">X</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="kt">f64</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">g</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;f64&quot;</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="mf">1.0.</span><span class="n">g</span><span class="p">();</span><span class="w"> </span><span class="c1">// currently prints &quot;f64&quot;</span>
<span class="w">    </span><span class="mf">1.</span><span class="n">g</span><span class="p">();</span><span class="w">   </span><span class="c1">// type error or print &quot;f64&quot;?</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="196802914"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196802914" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196802914">(May 07 2020 at 17:20)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> I think I'm still trying to wrap my head around the use case for this. The goal here is to...avoid typing <code>.0</code>?</p>



<a name="196802971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196802971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196802971">(May 07 2020 at 17:21)</a>:</h4>
<p>And in exchange for that, we get potential new inference issues and what seems like a lot of complexity?</p>



<a name="196802980"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196802980" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196802980">(May 07 2020 at 17:21)</a>:</h4>
<p>What am I missing?</p>



<a name="196803083"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196803083" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196803083">(May 07 2020 at 17:22)</a>:</h4>
<p>(That's leaving aside whether we <em>want</em> the compiler to accept <code>1</code> as a float, which I personally would prefer it didn't, but for the purposes of the questions above I'm ignoring that for the moment.)</p>



<a name="196805027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196805027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Sebastian Malton <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196805027">(May 07 2020 at 17:36)</a>:</h4>
<p><span class="user-mention" data-user-id="125254">@kennytm</span> Since it is only implemented for <code>f32</code> and <code>f64</code> the behaviour between <code>1.0.g()</code> and <code>1.g()</code> should be the same</p>



<a name="196805165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196805165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kennytm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196805165">(May 07 2020 at 17:37)</a>:</h4>
<p>so there would be 4 levels of inference: <code>i32 &gt; {integer} &gt; f64 &gt; {float}</code></p>



<a name="196806357"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196806357" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Sebastian Malton <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196806357">(May 07 2020 at 17:46)</a>:</h4>
<p>I don't know, in edition 2015 and 2018 are there already two for <code>1</code> and a different two for <code>1.0</code>?</p>



<a name="196806629"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196806629" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kennytm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196806629">(May 07 2020 at 17:48)</a>:</h4>
<p>in 2018 for <code>1</code> it is <code>i32 &gt; {integer}</code> and for <code>1.0</code> it is <code>f64 &gt; {float}</code></p>



<a name="196806680"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196806680" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kennytm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196806680">(May 07 2020 at 17:49)</a>:</h4>
<p>if <code>1.g()</code> is compilation error, we get 3 levels for 2021 <code>i32 &gt; {integer} &gt; {float}</code></p>



<a name="196820455"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196820455" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Sebastian Malton <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196820455">(May 07 2020 at 19:37)</a>:</h4>
<p>Well I think that it would be much more confusing if <code>1.g()</code> was a compilation error.</p>



<a name="196849848"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196849848" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196849848">(May 08 2020 at 01:24)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> one time I've wanted this is when implementing something by macro for both integers and floats -- then it's annoying that I can't write a literal that works with both.</p>



<a name="196849853"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196849853" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196849853">(May 08 2020 at 01:24)</a>:</h4>
<p>not a big deal to work around though</p>



<a name="196854467"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196854467" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196854467">(May 08 2020 at 03:23)</a>:</h4>
<p>Right, it's not the worst thing, but nearly every other major language lets you do it.</p>



<a name="196854615"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196854615" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196854615">(May 08 2020 at 03:27)</a>:</h4>
<p>Other weakly typed languages definitely. Do other strongly typed languages?</p>



<a name="196854935"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196854935" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196854935">(May 08 2020 at 03:37)</a>:</h4>
<p>Yes, Haskell does.</p>



<a name="196855107"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196855107" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196855107">(May 08 2020 at 03:42)</a>:</h4>
<p>In Haskell, any integer literal <code>n</code> is effectively the expression <code>fromInteger n</code> and has the type <code>Num a =&gt; a</code></p>
<p>or in approximate Rust terms, <code>n: impl Num</code></p>



<a name="196855120"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196855120" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196855120">(May 08 2020 at 03:43)</a>:</h4>
<p>and you can further constrain a particular literal of course, making it Int32 or Float or whatever specific number type</p>



<a name="196857213"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196857213" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196857213">(May 08 2020 at 04:35)</a>:</h4>
<p>I'm aware of what Haskell does. For the benefit of something like the macro case, we could easily add something like fromInteger. The question is whether we should do so by default.</p>



<a name="196861161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196861161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kennytm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196861161">(May 08 2020 at 06:18)</a>:</h4>
<blockquote>
<p>Other weakly typed languages definitely. Do other strongly typed languages?</p>
</blockquote>
<p>perhaps this question is more about what languages do <strong>not</strong> allow <code>1</code> as float. </p>
<p>Swift, Go, C#, Scala all can accept the dotless literal as float, not to mention C++ ("weak"), Python, TypeScript (no clear distinction between int and float), Haskell (see above).</p>



<a name="196865615"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196865615" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196865615">(May 08 2020 at 07:31)</a>:</h4>
<p>FWIW, at least C# and Python don't really "allow <code>1</code> as float" but rather have implicit conversions from ints to floats that affect all runtime values (not specifically literals). Well, Python doesn't have "implicit conversions" per se, but essentially all operators and functions that expect floats will gladly accept anything with a <code>__float__</code> method.</p>



<a name="196865927"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196865927" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kennytm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196865927">(May 08 2020 at 07:36)</a>:</h4>
<p>ok that means C# is "weak".</p>



<a name="196867932"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196867932" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196867932">(May 08 2020 at 08:03)</a>:</h4>
<p><span class="user-mention silent" data-user-id="224471">Lokathor</span> <a href="#narrow/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal/near/196788243" title="#narrow/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal/near/196788243">said</a>:</p>
<blockquote>
<p>Advanced float math actually does use hex float literals because "advanced float math" means "very carefully weave the line between what CPUs do and how IEEE works".</p>
</blockquote>
<p>there's also binary float literals to directly control the float bits which rust unfortunately does not support (but there's a crate for it)</p>



<a name="196879691"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196879691" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196879691">(May 08 2020 at 10:37)</a>:</h4>
<p>A bit of history:</p>
<p>When I first started working on Rust, the expression <code>22</code> <em>always</em> had type <code>isize</code> (then called <code>int</code>). You had to explicitly write <code>22_u32</code>. When we changed it to do inference, there was vociferous resistance, because things had to be explicit. We settled on inference and a lint for 'oversized' literals that don't fit the type they are ultimately inferred to be. (I actually.. am not entirely sure why a lint and not a hard error, I think there was some use case to sometimes abuse 2's complement notation or something..?)</p>



<a name="196879810"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196879810" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196879810">(May 08 2020 at 10:38)</a>:</h4>
<p>In particular, <span class="user-mention" data-user-id="239881">@Josh Triplett</span>, I want to push back on the notion that allowing <code>22</code> to be inferred to be <code>22.0</code> is truly "loosely typed". I think you can say that C's implicit upcasting of types and so forth is definitely loose, but inferring a fixed float type seems much different. (EDIT: Re-reading, I realize that you didn't say that it was loosely typed, though I think a connection was implied.)</p>



<a name="196880309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196880309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196880309">(May 08 2020 at 10:44)</a>:</h4>
<p>I guess it'd be good to list out specific errors you can get that <em>can't</em> be addressed through a lint that checks for extreme floating point issues (e.g., a number that can't be represented)</p>



<a name="196884452"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196884452" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196884452">(May 08 2020 at 11:35)</a>:</h4>
<blockquote>
<p>I guess it'd be good to list out specific errors you can get that can't be addressed through a lint that checks for extreme floating point issues (e.g., a number that can't be represented)</p>
</blockquote>
<p>Things like this feel both undesirable and inevitable if we allow float literals afaict. (if somewhat artificial tbh)</p>
<div class="codehilite"><pre><span></span><code>trait Foo {}
impl Foo for f32 {}
fn consume(_: impl Foo) {}
fn main() {
    consume(20_000_000 + 1); // When using f32, this calls consume with 20_000_000
}
</code></pre></div>



<a name="196885085"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196885085" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196885085">(May 08 2020 at 11:43)</a>:</h4>
<p>I'm not sure why that feels undesirable</p>



<a name="196885123"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196885123" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196885123">(May 08 2020 at 11:43)</a>:</h4>
<p>it's the arithmetic?</p>



<a name="196885175"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196885175" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196885175">(May 08 2020 at 11:44)</a>:</h4>
<p>oh, I see the comment</p>



<a name="196885183"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196885183" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196885183">(May 08 2020 at 11:44)</a>:</h4>
<p>ok, that's helpful :)</p>



<a name="196885239"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196885239" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196885239">(May 08 2020 at 11:44)</a>:</h4>
<p>although.. hmm.. I'm not sure ultimately it's any <em>more</em> surprising than 20_000_000.0 + 1.0 (EDIT: upon reflection I don't agree with this statement of mine; the <code>.0</code> is an obvious "tell" when inspecting the caller, without needing to look at the definition of <code>consume</code>)</p>



<a name="196885288"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196885288" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196885288">(May 08 2020 at 11:45)</a>:</h4>
<p>or <code>255 + 1</code> where you have <code>impl Foo for u8</code></p>



<a name="196886296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196886296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196886296">(May 08 2020 at 11:57)</a>:</h4>
<blockquote>
<p>or <code>255 + 1</code> where you have <code>impl Foo for u8</code></p>
</blockquote>
<p>That's a good point. I still think it's worse for floats, as integer overflow is far more noticeable <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span> <br>
I also really dislike floats in general, so I am somewhat biased here.</p>



<a name="196886754"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196886754" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196886754">(May 08 2020 at 12:02)</a>:</h4>
<p>^ A worse example  is <code>consume(20_000_000 + 1 + 1)</code>. Even if consume should take a f32 here, there is an actual difference between <code>(20_000_000 + 1 + 1) as f32</code> and <code>20_000_000.0 + 1.0 + 1.0</code>.</p>



<a name="196887384"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196887384" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196887384">(May 08 2020 at 12:10)</a>:</h4>
<p>Yeah, I definitely think there's an argument to be made for "the surprise factor of floats is so high that they are qualitatively different than integers" (and I think these examples are a good way to make it). That, combined with "floats are needed an order of magnitude less often" is perhaps enough to tilt the balance away from the surprise factor of "wait? there's a difference between 1 and 1.0?" (I've definitely sometimes spent time scratching my head over that...even though I ought to know better.)</p>



<a name="196908568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196908568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196908568">(May 08 2020 at 15:19)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal/near/196802914" title="#narrow/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal/near/196802914">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="224471">Lokathor</span> I think I'm still trying to wrap my head around the use case for this. The goal here is to...avoid typing <code>.0</code>?</p>
</blockquote>
<p>Just to respond to this, too, I think it's not fair to characterize as "avoid typing". The goal is to make numbers in Rust behave more like numbers in the real world, I imagine, and to avoid the "ergonomic hit" of compilation cycles driven just by "oh yeah gotta add a <code>.0</code> to please the compiler". Those cycles may be worthwhile, but I think the burden of proof should fall on us to show <em>it's worth it to force you to change your code, because it prevents bugs</em> (or <em>is easier to understand</em> or <em>can be implemented</em> or whatever), and not the reverse.</p>



<a name="196925529"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196925529" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196925529">(May 08 2020 at 17:29)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> I appreciate the explanation in those terms. To clarify something, that was intended as a genuine question. I didn't understand the use case for this at all, and my question was intended as "I must be missing something here".</p>



<a name="196925718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196925718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196925718">(May 08 2020 at 17:30)</a>:</h4>
<p>Separate from that, I do think your phrasing of "the surprise factor of floats is so high that they are qualitatively different than integers" is a much better way of putting my argument that I don't think we should let one token infer to either int or float, without stating that.</p>



<a name="196925844"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196925844" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196925844">(May 08 2020 at 17:31)</a>:</h4>
<p>I do think, for uses such as macros, we may need a way of writing "1 or 1.0, whichever the expression needs". But I'm inclined to make that <code>1.to_num()</code> or <code>1.into()</code>, not just <code>1</code>.</p>



<a name="196926142"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196926142" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196926142">(May 08 2020 at 17:34)</a>:</h4>
<p>Having just written a pile of code that uses <code>as</code> in many places (far more than I'd like), I think I can also further elaborate in response to the notion of "gotta add a <code>.0</code> to please the compiler". The question is, how often is the response "just add <code>.0</code>", and how often is the response going to be "yikes, it's a float? I need to think about this harder". Because with the mixing of integer types, it turns out that when I had a <code>u64</code> and needed a <code>u32</code>, the answer was almost never "gotta add <code>as u32</code> to please the compiler", but rather "hrm, how do I handle this, let me work backwards and figure out if the original thing should have been a u32 to begin with".</p>



<a name="196930252"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196930252" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196930252">(May 08 2020 at 18:06)</a>:</h4>
<p>Well, I started this topic when I'd just written 200+ doc tests with math in them that, on a test by test basis, used floating point and integer types of all sizes. And it really started to show the fiddly weaknesses involved (eg: <code>from</code> often also has very poor errors). And now I'm up to 409 doc tests any my position has not changed at all.</p>
<p>To answer your most recent question there:</p>
<ul>
<li>when using bound variables I quite often need to change data types with <code>as</code> or other methods, and sometimes it gives me pause and I reconsider a bit, perhaps convert all values to a common type before getting started with the math.</li>
<li>However when using literals I have never ever typed an integer, been told i needed a float there, and then and then changed the code to accommodate this new information and then changed the code in some way other than to add the .0 and immediately hit <em>compile</em>.</li>
</ul>
<p>I am sympathetic to the "20 million + 1" problem. However, that's also mostly a slightly separate problem with how float literals work. This example here:</p>
<div class="codehilite"><pre><span></span><code><span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;{}&quot;</span><span class="p">,</span><span class="w"> </span><span class="mf">20_000_001.0_</span><span class="k">f32</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>Will print <code>20000000</code> with no warning that your literal can't be exactly represented within <code>f32</code>.</p>
<p>So my own opinion is that <code>20_000_000+1</code> should fold to <code>20_000_001: {integer}</code> and then as the next step turning that integer to an f32 should fire off a warning that the value can't be exactly represented within the f32 type. However I also expect that such a system could then lead to some other edge case.</p>



<a name="196930569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196930569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196930569">(May 08 2020 at 18:09)</a>:</h4>
<p>we can detect at const prop time that <code>20_000_000.0_f32 + 1.0</code> does not do anything</p>



<a name="196930761"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196930761" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196930761">(May 08 2020 at 18:11)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> I do think there's value in warning when literal values can't be represented precisely.</p>



<a name="196930826"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196930826" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196930826">(May 08 2020 at 18:11)</a>:</h4>
<p>(deleted)</p>



<a name="196930913"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196930913" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196930913">(May 08 2020 at 18:12)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> but this kind of thing can happen in "ordinary" computations that happen to become elegible for const prop, so warning about it is on shaky ground / likely to give false positives</p>



<a name="196931214"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196931214" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196931214">(May 08 2020 at 18:14)</a>:</h4>
<p>indeed, that is a problem, but the above example seems awefully rare, I would expect this to only be an issue when more complexity is involved, as it isn't obvious to the user what's going on</p>



<a name="196931306"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196931306" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196931306">(May 08 2020 at 18:15)</a>:</h4>
<p>does float math even run at const time? I thought it did not and would never because of the dreaded non-determinism</p>



<a name="196931517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196931517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196931517">(May 08 2020 at 18:17)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> GCC, at least, runs float math at compile time, and has some very careful libraries that exist to do so deterministically.</p>



<a name="196931773"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196931773" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196931773">(May 08 2020 at 18:19)</a>:</h4>
<p>To be clear I would love to have floats at const times  and even to emulate float intrinsics at compile time, and so on.</p>
<p>I was just previously told by various folks that it is (loosely) "probably never gonna happen, because it's non-determinism"</p>



<a name="196932198"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196932198" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196932198">(May 08 2020 at 18:23)</a>:</h4>
<p>idk what const prop does or should do, but for better or worse, float arithmetic in constant expressions <em>is</em> supported.</p>



<a name="196932199"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196932199" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196932199">(May 08 2020 at 18:23)</a>:</h4>
<p>since <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=5eb83b14d13b63470af9336e9b2ae459" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=5eb83b14d13b63470af9336e9b2ae459">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=5eb83b14d13b63470af9336e9b2ae459</a> compiles, we can be sure that it works at const eval time. We may not be doing it at const prop time, but we most definitely could</p>



<a name="196932320"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196932320" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196932320">(May 08 2020 at 18:24)</a>:</h4>
<p>It's supported in a const declaration expression but not a const fn body.</p>



<a name="196932513"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196932513" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196932513">(May 08 2020 at 18:26)</a>:</h4>
<p>well, <em>stable</em> that is.</p>
<p>anyway that's maybe a little off topic for this particular thread.</p>



<a name="196933518"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196933518" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196933518">(May 08 2020 at 18:35)</a>:</h4>
<p>By the way, this thread is making me think.</p>



<a name="196933531"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196933531" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196933531">(May 08 2020 at 18:35)</a>:</h4>
<p>I want to beef up the lang-team website to have a lot more info</p>



<a name="196933541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196933541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196933541">(May 08 2020 at 18:35)</a>:</h4>
<p>including design notes and thoughts that collect over time about particular questions</p>



<a name="196933558"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196933558" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196933558">(May 08 2020 at 18:35)</a>:</h4>
<p>I was thinking that after major threads like this that occur on Zulip, we should make a point to write-up conclusions</p>



<a name="196933575"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196933575" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196933575">(May 08 2020 at 18:35)</a>:</h4>
<p>I'm going to try and do just a bit of that for this thread</p>



<a name="196933657"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196933657" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196933657">(May 08 2020 at 18:36)</a>:</h4>
<p>to show what I mean, but I think it should be standard practice -- in fact, i'm even getting grandiose ideas of trying to create a set of "wg-scribes" or something who generally have that role</p>



<a name="196933664"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196933664" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196933664">(May 08 2020 at 18:36)</a>:</h4>
<p>but let's start small :)</p>



<a name="196933693"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196933693" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196933693">(May 08 2020 at 18:36)</a>:</h4>
<p>I'm sick of having the same conversations over and over and rediscovering the same constraints :P</p>



<a name="196934278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196934278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196934278">(May 08 2020 at 18:42)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal/near/196931517" title="#narrow/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal/near/196931517">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="224471">Lokathor</span> GCC, at least, runs float math at compile time, and has some very careful libraries that exist to do so deterministically.</p>
</blockquote>
<p>We use <span class="user-mention" data-user-id="119009">@eddyb</span> 's Rust port of LLVM's libapfloat for this</p>



<a name="196934301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196934301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196934301">(May 08 2020 at 18:42)</a>:</h4>
<p>so, I think basically the same as GCC</p>



<a name="196934339"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196934339" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196934339">(May 08 2020 at 18:42)</a>:</h4>
<p>well, the same as Clang, but yeah :P</p>



<a name="196934374"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196934374" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196934374">(May 08 2020 at 18:42)</a>:</h4>
<p>I mean on the level of "careful lib for deterministic float math"</p>



<a name="196934422"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196934422" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196934422">(May 08 2020 at 18:43)</a>:</h4>
<p>Miri-the-tool will use host float operations to fill in some gaps in libapfloat, but rustc itself will never do that</p>



<a name="196934433"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196934433" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196934433">(May 08 2020 at 18:43)</a>:</h4>
<blockquote>
<p>we can detect at const prop time that 20_000_000.0_f32 + 1.0 does not do anything</p>
</blockquote>
<p>This is not always possible though <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>
<div class="codehilite"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">Foo</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">_</span>: <span class="nc">T</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">T</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">trait</span><span class="w"> </span><span class="n">Delegate</span>: <span class="nc">Foo</span><span class="o">&lt;</span><span class="kt">i32</span><span class="o">&gt;</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">Foo</span><span class="o">&lt;</span><span class="kt">f32</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">test</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">(</span><span class="n">bar</span>: <span class="kp">&amp;</span><span class="nc">dyn</span><span class="w"> </span><span class="n">Delegate</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">consume</span><span class="p">(</span><span class="n">bar</span><span class="p">.</span><span class="n">foo</span><span class="p">(</span><span class="mi">20_000_000</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>edit: fixed the example</p>



<a name="196935637"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196935637" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196935637">(May 08 2020 at 18:54)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> <span class="user-mention" data-user-id="239881">@Josh Triplett</span> <span class="user-mention" data-user-id="224471">@Lokathor</span> btw <code>rustc_apfloat</code>:</p>
<ul>
<li>only uses non-<code>core</code> functionality (heap allocation) for string&lt;-&gt;float conversions (<code>core</code>'s own <code>FromStr</code> uses stack-allocated bigints, maybe I should try that)</li>
<li>has <code>#![forbid(unsafe_code)]</code></li>
<li>has no global state</li>
</ul>



<a name="196935694"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196935694" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196935694">(May 08 2020 at 18:54)</a>:</h4>
<p>AFAIK this effectively makes it "pure" :P</p>



<a name="196935810"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196935810" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196935810">(May 08 2020 at 18:55)</a>:</h4>
<p>might be able to start using <code>const fn</code> in it except for traits (<code>Iterator</code> is the worst I guess)</p>



<a name="196936056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196936056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196936056">(May 08 2020 at 18:56)</a>:</h4>
<p>(don't copy what core::dec2flt does, it has arbitrary limitations and is much slower than it has to be)</p>



<a name="196936177"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196936177" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196936177">(May 08 2020 at 18:57)</a>:</h4>
<p>I strongly suspect <code>rustc_apfloat</code> is slower given how naive it is, but if I would do the stack thing, it would probably be behind a <code>not(feature(alloc))</code> or something</p>



<a name="196936433"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196936433" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196936433">(May 08 2020 at 18:59)</a>:</h4>
<p>Much of the slowness in the libcore impl is in the bignum operations, fwiw</p>



<a name="196936952"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196936952" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196936952">(May 08 2020 at 19:03)</a>:</h4>
<p>I didn't implement any of the APInt optimizations for e.g. division, except for short division (idk if they have it as a special case or what), which is when your divisor fits in whatever bigint unit ("limb") you're using, true for most of the common divisors</p>



<a name="196937241"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196937241" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196937241">(May 08 2020 at 19:06)</a>:</h4>
<p>and that was to fix a regression when we switched to <code>rustc_apfloat</code> :P</p>



<a name="196937700"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196937700" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196937700">(May 08 2020 at 19:09)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> on using something like <code>1.into()</code>, you still need a type for that <code>1</code> -- <code>u8</code> works into everything but <code>i8</code></p>



<a name="196937886"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196937886" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196937886">(May 08 2020 at 19:11)</a>:</h4>
<p><code>1 as $num</code> is the lazy macro solution</p>



<a name="196938045"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196938045" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196938045">(May 08 2020 at 19:12)</a>:</h4>
<p><code>$num</code>?</p>



<a name="196938085"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196938085" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196938085">(May 08 2020 at 19:13)</a>:</h4>
<p>Is that a macro argument supplying the type?</p>



<a name="196939712"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196939712" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196939712">(May 08 2020 at 19:27)</a>:</h4>
<p>OK folks</p>



<a name="196939736"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196939736" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196939736">(May 08 2020 at 19:27)</a>:</h4>
<p>I created this PR that summarizes some key points and takeaways: </p>
<p><a href="https://github.com/rust-lang/lang-team/pull/16" title="https://github.com/rust-lang/lang-team/pull/16">https://github.com/rust-lang/lang-team/pull/16</a></p>



<a name="196939799"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196939799" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196939799">(May 08 2020 at 19:28)</a>:</h4>
<p>It is by no means exhaustive. I would <em>love</em> it if people who participated in this meeting went and suggested edits.</p>



<a name="196939824"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196939824" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196939824">(May 08 2020 at 19:28)</a>:</h4>
<p>As I was saying, I think that -- eventually -- every substantial conversation that takes place here  should conclude with a PR of this kind that updates and records the information :)</p>



<a name="196939832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196939832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196939832">(May 08 2020 at 19:28)</a>:</h4>
<p>but let's just start with this one</p>



<a name="196939940"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196939940" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196939940">(May 08 2020 at 19:29)</a>:</h4>
<p>Good summary, thank you.</p>



<a name="196939963"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196939963" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196939963">(May 08 2020 at 19:29)</a>:</h4>
<p>That'll help the next time this comes up.</p>



<a name="196939995"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196939995" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196939995">(May 08 2020 at 19:29)</a>:</h4>
<p>It doesn't have a conclusion, but then, neither did the discussion here.</p>



<a name="196942200"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196942200" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196942200">(May 08 2020 at 19:49)</a>:</h4>
<p>Indeed, it wasn't meant to "conclude"</p>



<a name="196944984"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196944984" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196944984">(May 08 2020 at 20:12)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> I was concerned I didn't capture the "pro" side very well btw :)</p>



<a name="196950767"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196950767" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196950767">(May 08 2020 at 21:07)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> yes I meant that like a macro argument <code>$num:ty</code></p>



<a name="196950938"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196950938" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196950938">(May 08 2020 at 21:09)</a>:</h4>
<p>hm you might even be able to get away with "5 as _" right?</p>



<a name="196951056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196951056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196951056">(May 08 2020 at 21:10)</a>:</h4>
<p>/me stares.</p>



<a name="196951066"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196951066" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196951066">(May 08 2020 at 21:10)</a>:</h4>
<p>/me stares harder.</p>



<a name="196951117"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196951117" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196951117">(May 08 2020 at 21:10)</a>:</h4>
<p>/me is impressed with Rust type inference.</p>



<a name="196951575"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196951575" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196951575">(May 08 2020 at 21:15)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> <code>as _</code> would probably work, but I usually do have the type at hand because I'm writing some <code>impl XYZ for $num</code></p>



<a name="196951584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196951584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196951584">(May 08 2020 at 21:15)</a>:</h4>
<p>sure, yes</p>



<a name="196954461"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196954461" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196954461">(May 08 2020 at 21:49)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> I can comment on the PR later perhaps with more persuasive words. My ISP is dead right now and I was hoping it would be fixed around the top of the hour but it was not. Until then I'm stuck on just a phone.</p>



<a name="196954657"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196954657" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196954657">(May 08 2020 at 21:51)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> ok -- I may also just land and you can open a follow-up PR</p>



<a name="196954709"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196954709" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196954709">(May 08 2020 at 21:52)</a>:</h4>
<p>yeah no worries</p>



<a name="196977117"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Edition%20Request%3A%20let%20%601%60%20be%20a%20float%20literal/near/196977117" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kennytm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Edition.20Request.3A.20let.20.601.60.20be.20a.20float.20literal.html#196977117">(May 09 2020 at 06:49)</a>:</h4>
<p>with <code>5 as _</code> you may end up with <code>5 as *const String</code> if you can't control the <code>$num</code> <span aria-label="upside down" class="emoji emoji-1f643" role="img" title="upside down">:upside_down:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>